package com.Test;

import java.util.regex.Pattern;

public class Test07 {
    public static void main(String[] args) {

        String a = "kk";
        String b = "0.456";
        String c = "0.789";

        System.out.println(isDouble(a)); // false
        System.out.println(isDouble(b)); // true
        System.out.println(isDouble(c)); // true
    }


    /**
     * 判断是否为整数
     *
     * @param str
     * @return
     */
    public static boolean isInteger(String str) {
        if (null == str || "".equals(str)) {
            return false;
        }
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }


    /**
     * 判断是否为浮点数
     *
     * @param str
     * @return
     */
    public static boolean isDouble(String str) {
        if (null == str || "".equals(str)) {
            return false;
        }
        Pattern pattern = Pattern.compile("^[-\\+]?[.\\d]*$");
        return pattern.matcher(str).matches();
    }
}
